package com.afkt.project.ui.slice;

import com.afkt.project.base.app.BaseActivity;
import com.afkt.project.ui.ShapeImage;
import com.ohos.afkt.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;

/**
 * detail: Material ShapeableImageView
 *
 * @author Ttt
 * <pre>
 *     描边需设置 padding 大小为描边宽度一半, 否则显示不全
 * </pre>
 */
public class ShapeableImageViewActivity extends BaseActivity {

    private ShapeImage image1;
    private ShapeImage image2;
    private ShapeImage image3;
    private ShapeImage image4;
    private ShapeImage image5;
    private ShapeImage image6;
    private ShapeImage image7;
    private ShapeImage image8;
    private ShapeImage image9;

    private DirectionalLayout bar_Layout;
    private DirectionalLayout bar;
    private Image shapeImage_return;

    @Override
    protected int baseLayoutId() {
        return ResourceTable.Layout_activity_shapeable_image_view;
    }

    @Override
    protected void initView() {
        image1 = (ShapeImage) findComponentById(ResourceTable.Id_shapeImage_1);
        image2 = (ShapeImage) findComponentById(ResourceTable.Id_shapeImage_2);
        image3 = (ShapeImage) findComponentById(ResourceTable.Id_shapeImage_3);
        image4 = (ShapeImage) findComponentById(ResourceTable.Id_shapeImage_4);
        image5 = (ShapeImage) findComponentById(ResourceTable.Id_shapeImage_5);
        image6 = (ShapeImage) findComponentById(ResourceTable.Id_shapeImage_6);
        image7 = (ShapeImage) findComponentById(ResourceTable.Id_shapeImage_7);
        image8 = (ShapeImage) findComponentById(ResourceTable.Id_shapeIamge_8);
        image9 = (ShapeImage) findComponentById(ResourceTable.Id_shapeImage_9);

        image1.setPixelMapAndCircle(ResourceTable.Media_bg_wallpaper);
        image2.setPixelMapAndRoundRectAndStroke(ResourceTable.Media_bg_wallpaper, 60);
        image3.setPixelMapClip(ResourceTable.Media_bg_wallpaper, 70);
        image4.setPixelMapCube(ResourceTable.Media_bg_wallpaper);
        image5.setPixelMapSector(ResourceTable.Media_bg_wallpaper);
        image6.setPixelMapTwoClip(ResourceTable.Media_bg_wallpaper);
        image7.setPixelMapBesselCurve(ResourceTable.Media_bg_wallpaper);
        image8.setPixelMapOvalAndClip(ResourceTable.Media_bg_wallpaper);
        image9.setPixelMapTwoClipAndRadius(ResourceTable.Media_bg_wallpaper, 60);

        bar_Layout = (DirectionalLayout) findComponentById(ResourceTable.Id_shapeImage_layout);
        bar = (DirectionalLayout) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_shapeimage_bar, null, false);
        bar_Layout.addComponent(bar);
        shapeImage_return = (Image) bar.findComponentById(ResourceTable.Id_shapeImage_return);
    }

    @Override
    protected void initListener() {
        shapeImage_return.setClickedListener(component -> onBackPressed());
    }

    @Override
    protected void onBackground() {
        bar_Layout.removeComponent(bar);
        super.onBackground();
    }
}
